import { Chip, Tooltip, useTheme } from '@mui/material';
import { CheckIndeterminateIcon, EditIcon, LogoXtmOneIcon } from 'filigran-icon';

import { useFormatter } from '../../../../components/i18n';
import { type DetectionRemediation } from '../../../../utils/api-types';

export interface Props { author_rule: DetectionRemediation['author_rule'] }

const DetectionRemediationInfo = ({ author_rule }: Props) => {
  const theme = useTheme();
  const { t } = useFormatter();

  let label;
  let color;
  let icon;

  if (author_rule === 'AI_OUTDATED') {
    label = t('Payload changed since rule was edited');
    color = theme.palette.warning.main;
    icon = <CheckIndeterminateIcon fontSize="small" />;
  } else if (author_rule === 'AI') {
    label = t('Rules generated by AI');
    color = theme.palette.ai.main;
    icon = <LogoXtmOneIcon fontSize="small" />;
  } else if (author_rule === 'HUMAN') {
    label = t('Rules written by Human');
    color = theme.palette.secondary.main;
    icon = <EditIcon fontSize="small" />;
  }

  return (
    <Tooltip title={label}>
      <Chip
        size="small"
        variant="outlined"
        icon={icon}
        label={label}
        sx={{
          color,
          'borderColor': color,
          '& .MuiChip-icon': {
            width: 12,
            height: 12,
            marginLeft: theme.spacing(0.5),
            color,
          },
        }}
      />
    </Tooltip>
  );
};
export default DetectionRemediationInfo;
